﻿using Assets.Scripts.DL.Consts;
using Assets.Scripts.DL.Enemy.CommonEnemy;
using Assets.Scripts.DL.Mgrs;
using UnityEngine;

namespace Assets.Scripts.DL.Enemy.YaSuo {
	public class YasuoE : CommonState<YasuoController> {
		readonly Timer _ETimer = new();
		readonly Timer cdtimer;
		public YasuoE(YasuoController controller, StateEnum stateName) : base(controller, stateName) {
			cdtimer = _controller.StateData.AtkCdRecoder[StateName];
			//Player != Null在ATKHFSM中判断
			AddConditionToSelf(() => /*_controller.Player != null &&*/ cdtimer.Elapsed > _controller.ECd);
		}

		public override void Enter() {
			var px = _controller.GetPlayerPos().x;
			var x = _controller.transform.position.x;
			var dir = px > x ? 1 : -1;
			_controller.ChangeFaceDir(dir);

			_controller.Velocity = new UnityEngine.Vector2(dir * _controller.ESpeed, 0);
			AudioManager.Play(_controller.Voice1, AudioStr.EAudio);
			PoolTools.MakeShadowSyn(_controller.Velocity.normalized, _controller.SpriteRenderer.sprite, _controller.transform, "Blue");
			_ETimer.Reset();
			cdtimer.Reset();
			//音效
		}

		public override void Exit() {
			_controller.Velocity = UnityEngine.Vector2.zero;
		}

		public override void Update() {
			//Debug.Log(_controller.Velocity);

			if (_ETimer.Elapsed > _controller.ETime) {
				//Debug.Log(_controller.Velocity);
				_controller.StateData.AtkOver = true;
			}
		}
	}
}
